const KoaRouter = require("@koa/router");
const { verifyAuth } = require("../middleware/authority.middleware");
const {
  releaseAccommodation,
  getAccommodation,
  getAccommodationByHot,
  likeAccommodation,
  saveAccommodation,
  getSaveAccommodation,
  reservation,
  getReservation,
} = require("../controller/accommodation.controller");
const { verifyBody, verifyQuery } = require("../middleware/verify.middleware");
const {
  accommodation_Parameter,
  paging_Parameter,
  save_Accommodation_Parameter,
  reservation_Parameter,
} = require("../config/parameter");

// 1. 创建路由对象
const accommodationRouter = new KoaRouter({ prefix: "/accommodation" });

// 2. 定义路由中的映射
// 发布
accommodationRouter.post(
  "/releaseAccommodation",
  verifyAuth,
  verifyBody(accommodation_Parameter),
  releaseAccommodation
);
// 获取
accommodationRouter.get(
  "/getAccommodation",
  verifyQuery(paging_Parameter),
  getAccommodation
);
// 按热度获取
accommodationRouter.get(
  "/getAccommodationByHot",
  verifyQuery(paging_Parameter),
  getAccommodationByHot
);
// 模糊查询
accommodationRouter.get(
  "/likeAccommodation/:keyWord",
  verifyQuery(paging_Parameter),
  likeAccommodation
);
// 收藏
accommodationRouter.post(
  "/saveAccommodation",
  verifyAuth,
  verifyQuery(save_Accommodation_Parameter, true),
  saveAccommodation({ type: "收藏", method: "post" })
);
// 获取是否收藏
accommodationRouter.get(
  "/saveAccommodation",
  verifyAuth,
  verifyQuery(save_Accommodation_Parameter, true),
  saveAccommodation({ type: "获取收藏", method: "get" })
);
// 取消收藏
accommodationRouter.delete(
  "/saveAccommodation",
  verifyAuth,
  verifyQuery(save_Accommodation_Parameter, true),
  saveAccommodation({ type: "取消收藏", method: "delete" })
);
// 获取用户的收藏
accommodationRouter.get(
  "/getSaveAccommodation",
  verifyAuth,
  verifyQuery(paging_Parameter, true),
  getSaveAccommodation
);
// 下单
accommodationRouter.post(
  "/reservation",
  verifyAuth,
  verifyBody(reservation_Parameter),
  reservation({ type: "下单", method: "post" })
);
// 取消下单
accommodationRouter.delete(
  "/reservation",
  verifyAuth,
  verifyBody(reservation_Parameter),
  reservation({ type: "取消下单", method: "delete" })
);
// 获取用户的下单
accommodationRouter.get(
  "/getReservation",
  verifyAuth,
  verifyQuery(paging_Parameter, true),
  getReservation
);

module.exports = accommodationRouter;
